/*************************************************************************
	> File Name: P1216.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-04-09 09:49:40
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int get_max(vector<vector<int>> &num) {
    int m = num.size(), n = num[0].size();
    vector<vector<int>> dp(m, vector<int>(n));
    for (int j = 0; j < n; j++) {
        dp[m - 1][j] = num[m - 1][j];
    }
    for (int i = m - 2; i >= 0; i--) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j + 1]) + num[i][j];
        }
    }
    return dp[0][0];
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> arr(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            scanf("%d", &arr[i][j]);
        }
    }
    cout << get_max(arr) << endl;
    return 0;
}
